package com.gengzp.common.enums;

import com.gengzp.common.exception.BusinessException;
import lombok.Getter;

import java.util.Objects;

/**
 * @ClassName IterationStatusEnum
 * @Description 迭代状态枚举类
 * @Author gengzp
 * @Date 2025/10/11 16:12
 */
@Getter
public enum IterationStatusEnum {

    UN_STARTED(0, "未开始"),
    IN_PROGRESS(1, "开发中"),
    COMPLETED(2, "已完成");


    IterationStatusEnum(int code, String value) {
        this.code = code;
        this.value = value;
    }

    private final int code;
    private final String value;

    public static String getValueByCode(int code) {
        for (IterationStatusEnum v : IterationStatusEnum.values()) {
            if (Objects.equals(v.getCode(), code)) {
                return v.getValue();
            }
        }
        throw BusinessException.get(String.format("枚举值不关联, 枚举类: %s,枚举值: %s", IterationStatusEnum.class, code));
    }

    public static int getCodeByValue(String value) {
        for (IterationStatusEnum v : IterationStatusEnum.values()) {
            if (Objects.equals(v.getValue(), value)) {
                return v.getCode();
            }
        }
        throw BusinessException.get(String.format("枚举值不关联, 枚举类: %s,枚举值: %s", IterationStatusEnum.class, value));
    }

}
